<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2020/1/29
  Time: 13:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>流程审核</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<script src="/layui/layui.js" charset="utf-8"></script>
<script src="/js/jquery-3.4.1.js" charset="utf-8"></script>
<body style="padding: 10px;background-color: rgb(236,240,245);">
<h1 style="margin-bottom: 20px;">${param.process_title}</h1>
<!-- 表单区+返回按钮 -->
<div style="background-color: white;">
    <div class="layui-row">
        <!-- 返回按钮 -->
        <div class="layui-col-xs1" style="padding-left: 10px;padding-top: 10px;">
            <button type="button" class="layui-btn layui-btn-sm layui-btn-normal" onclick="history.go(-1)">
                <i class="layui-icon layui-icon-left">返回</i>
            </button>
        </div>
    </div>
    <!-- 蓝色分割线 -->
    <hr class="layui-bg-blue">
    <h2 style="margin-left: 50px;margin-bottom: -40px">审核进度：<c:if test="${param.cur_auditType == 0}">部门经理审核</c:if><c:if test="${param.cur_auditType == 1}">人事经理审核</c:if><c:if test="${param.cur_auditType == 2}">财务经理审核</c:if></h2>
    <div class="layui-progress layui-progress-big" style="margin: 50px">
        <div class="layui-progress-bar" lay-percent="${param.progress_level}/3"></div>
    </div>
    <form class="layui-form layui-form-pane" action="/auditProcess/auditProcess.do" style="padding-left: 110px;">
        <!-- 当前审核类型：0-部门经理审核，1-人事经理审核，2-财务经理审核 -->
        <input id="cur_auditType" name="cur_auditType" value="${param.cur_auditType}" style="display: none">
        <!-- 下一步审核类型：0-流程已结束，1-人事经理审核，2-财务经理审核 -->
        <input id="next_auditType" name="next_auditType" value="${param.next_auditType}" style="display: none">
        <!-- 流程类型 -->
        <input name="process_type" value="${param.process_type}" style="display: none">
        <!-- 审核进度 -->
        <input name="progress_level" value="${param.progress_level + 1}" style="display: none">
        <!-- 流程id -->
        <input name="process_id" value="${param.process_id}" style="display: none">
        <!-- 第一排 -->
        <div class="layui-form-item">
            <div class="layui-inline" style="width: 45%">
                <label class="layui-form-label">审核状态</label>
                <div class="layui-input-block">
                    <select name="audit_status_id" lay-verify="required">
                        <option value=""></option>
                        <c:forEach var="item" items="${audit_status}">
                            <c:if test="${item.status_name != '未处理' and item.status_name != '处理中'}">
                                <option value="${item.status_id}">${item.status_name}</option>
                            </c:if>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <div class="layui-inline" style="width: 45%">
                <label class="layui-form-label" style="width: 120px">下一步审核人</label>
                <div class="layui-input-block" style="margin-left: 120px">
                    <input id="audit_user_id" name="audit_user_id" style="display: none">
                    <input id="audit_user_name" readonly lay-verify="auditUser" class="layui-input">
                    <button type="button" class="layui-btn layui-btn-xs" onclick="openUser()" style="position: absolute;top: 8px;right: 10px">添加</button>
                </div>
            </div>
        </div>
        <!-- 第二排 -->
        <div class="layui-form-item">
            <div class="layui-inline" style="width: 45%;margin-top: 20px;">
                <label class="layui-form-label">意见</label>
                <textarea name="advice" required lay-verify="required" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <!-- 功能按钮 -->
        <div class="layui-form-item" style="padding: 15px 0;">
            <div class="layui-inline">
                <button class="layui-btn" lay-submit lay-filter="submitBtn">保存</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
</body>
<script>
    var selected;
    //form模块
    layui.use(['form','element'], function(){
        var form = layui.form;

        //监听提交
        form.on('submit(submitBtn)', function(data){

            return true;
        });
        form.verify({
            auditUser: function(value, item) { //value：表单的值、item：表单的DOM对象

                if($("#next_auditType").val() == '0' || selected == '11'){

                }else {
                    if(value == null || value == ''){

                        return '请选择下一步审核人！';
                    }
                }

            }
        });
        form.on('select()', function(data){

            selected = data.value; //得到被选中的值
        });
    });

    function openUser() {

        var next_auditType = $("#next_auditType").val();
        if(next_auditType != 0){
            var dept_id;
            var dept_name;
            if(next_auditType == 1){
                dept_id = 8;
                dept_name = '人力资源部';
            }else{
                dept_id = 9;
                dept_name = '资金财务部';
            }
            layer.open({
                title:'下一步审核人',
                type: 2,//弹出一个iframe层
                content: '/jsp/processManage/userListPanel.jsp?dept_id='+dept_id+'&dept_name='+dept_name+'&position_level=1',
                area: ['900px', '500px'],
                btn: ['确定', '取消'],
                yes:function (index, layero) {
                    //弹出层body的jQuery对象
                    var body = layer.getChildFrame("body",index);
                    //选中的员工id、name
                    var user_id = body.find("#selectedUserId").val();
                    var real_name = body.find("#selectedUserName").val();

                    $("#audit_user_id").val(user_id);
                    $("#audit_user_name").val(real_name);

                    layer.close(index);
                }
            });
        }else {
            layer.msg("该流程以结束，没有下一步");
        }
    }
</script>
</html>
